package com.zq.order.controller;


import cn.hutool.log.Log;
import com.zq.common.util.Result;
import com.zq.order.dao.dto.OrderInfoDto;
import com.zq.order.dao.vo.TradeVo;
import com.zq.order.service.IOrderItemService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单项信息 前端控制器
 * </p>
 *
 * @author 张乔
 * @since 2025-05-20
 */
@RestController
@RequestMapping("/order/order-item")
public class OrderItemController {


    @Resource
    private IOrderItemService orderItemService;

//    用户确认下单
    @GetMapping("auth/trade")
    public Result<TradeVo> trade(@RequestHeader("userToken")String token) {
        TradeVo tradeVo = orderItemService.getTrade(token);
        return Result.successData(tradeVo);
    }

    @GetMapping("trade/byOrderId/{orderId}")
    public Result<TradeVo> tradeByOrderId(@RequestHeader("userToken")String token,
                                          @PathVariable("orderId") Long orderId) {
        TradeVo tradeVo = orderItemService.getTradeByOrderId(token,orderId);
        return Result.successData(tradeVo);
    }

    @GetMapping("trade/bySkuId/{skuId}")
    public Result<TradeVo> tradeByOrderIds(@RequestHeader("userToken")String token,
                                          @PathVariable("skuId") Long skuId) {
        TradeVo tradeVo = orderItemService.getTradeBySkuId(token,skuId);
        return Result.successData(tradeVo);
    }

//    获取购物车信息
    @GetMapping("getAll/cart")
    public Result<TradeVo> getALlCart(@RequestHeader("userToken")String token) {
        TradeVo tradeVo = orderItemService.getALlCart(token);
        return Result.successData(tradeVo);
    }

    @PostMapping("create/order")
    public  Result<Long> createOrder(@RequestHeader("userToken")String token,
                                       @RequestBody OrderInfoDto orderInfoDto) {
        Long order = orderItemService.createOrder(token, orderInfoDto);
        return Result.successData(order);
    }
    @PostMapping("update/orderType/{orderId}")
    public  Result<String> updateOrderType(@RequestHeader("userToken")String token,
                                      @PathVariable("orderId") Long orderId,
                                           @RequestParam(value = "paymentType",required = false) String paymentType) {
        orderItemService.updateOrderType(token,orderId, paymentType);
        return Result.success();
    }

}
